<template>
  <div class="login">
    <div class="login_box">
      <el-form
        :model="loginForm"
        ref="LoginFormRef"
        label-width="0px"
        class="login_from"
      >
        <el-form-item prop="username">
          <el-input
            v-model="loginForm.username"
            prefix-icon="iconfont icon-user"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            prefix-icon="iconfont icon-3702mima"
          ></el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      loginForm: {
        username: 'admin',
        password: '123456'
      }
    }
  },
  methods: {
    login () {
      this.$http.post('/login', this.loginForm).then((res) => {
        if (res.data.code === 1) {
          this.$router.push('/home')
          this.$message.success(res.data.data.message)
          window.localStorage.setItem('token', res.data.data.token)
        } else {
          this.$message.error(res.data.data.message)
        }
      })
    }
  }
}
</script>

<style scoped>
.login {
  width: 100%;
  height: 100%;
  background: #f2f2f2;
}

.login_box {
  width: 350px;
  height: 200px;
  background: #fff;
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 15px;
  transform: translate(-50%, -50%);
  border-radius: 20px;
}

.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}
.btns {
  display: flex;
  justify-content: flex-end;
}
</style>
